<template>
    <view>
        <custom><template #backText>店铺信息</template></custom>
        <nBar title="固定信息"></nBar>
        <nFormItem key="form_seller_info_name" title="商家名称" :value="$store.state.user.identity_info.seller_info.name"></nFormItem>
        <nFormItem key="form_seller_info_province_city_area_name" title="所在地区" :value="$store.state.user.identity_info.seller_info.province_city_area_name"></nFormItem>
        <nFormItem key="form_seller_info_parent_nickname" title_em="6" title="商家的推荐人" :value="$store.state.user.identity_info.seller_info.parent_nickname || '没有推荐人'"></nFormItem>
        <nFormItem key="form_seller_info_annual_fee_end_date" title_em="8" title="商家年费到期日期" v-if="$store.state.user.identity_info.seller_info.is_seller == 1">
            <template #right>
                <text v-if="$store.state.user.identity_info.seller_info.annual_fee_end_date>0">
                    {{$store.state.user.identity_info.seller_info.annual_fee_end_date}}
                </text>
                <nButton title="商家缴年费" uri="/seller/pay/annualFee?seller_type=0"></nButton>
            </template>
        </nFormItem>
        <nFormItem key="form_seller_info_annual_fee_end_date_firm" title_em="8" title="企业年费到期日期" v-if="$store.state.user.identity_info.seller_info.is_firm == 1">
            <template #right>
                <text v-if="$store.state.user.identity_info.seller_info.annual_fee_end_date_firm>0">
                    {{$store.state.user.identity_info.seller_info.annual_fee_end_date_firm}}
                </text>
                <nButton title="企业缴年费" uri="/seller/pay/annualFee?seller_type=1"></nButton>
            </template>
        </nFormItem>
        <nFormItem key="form_seller_info_is_pay_open_express" title_em="8" title="商家开通全国邮寄" v-if="$store.state.user.identity_info.seller_info.is_seller == 1&&$store.state.user.identity_info.seller_info.annual_fee_end_date>0">
            <template #right>
                <text v-if="$store.state.user.identity_info.seller_info.is_pay_open_express>0">
                    已开通
                </text>
                <nButton v-else title="商家开通邮寄" uri="/seller/pay/openExpress?seller_type=0"></nButton>
            </template>
        </nFormItem>
        <nFormItem key="form_seller_info_is_pay_open_express_firm" title_em="8" title="企业开通全国邮寄" v-if="$store.state.user.identity_info.seller_info.is_firm == 1&&$store.state.user.identity_info.seller_info.annual_fee_end_date_firm>0">
            <template #right>
                <text v-if="$store.state.user.identity_info.seller_info.is_pay_open_express_firm>0">
                    已开通
                </text>
                <nButton v-else title="企业开通邮寄" uri="/seller/pay/openExpress?seller_type=1"></nButton>
            </template>
        </nFormItem>
        <nBar title="基本信息"></nBar>
        <nFormItem key="form_open_start_time" type="time_to_time" title="营业时间" :data.sync="data" field="open_start_time" field2="open_end_time"></nFormItem>
        <nFormItem key="form_is_to_shop_is_same_city_tmp_is_express" type="checkbox_fields" title="配送方式" :data.sync="data" :checkbox_values="{
            is_express: '全国邮寄',
            is_same_city_tmp: '同城配送',
            is_to_shop: '到店自取',
        }"></nFormItem>
        <nFormItem key="form_same_city_price" v-if="data.form.is_same_city_tmp == 1" title_em="5" title="同城配送费" :data.sync="data" field="same_city_price" format="digit"></nFormItem>
        <nFormItem key="form_is_same_city" v-if="data.form.is_same_city_tmp == 1" title_em="10" title="同城配送距离（公里）" :data.sync="data" field="is_same_city" format="number"></nFormItem>
        <nFormItem key="form_contact_phone" title="联系电话" :data.sync="data" field="contact_phone"></nFormItem>
        <nFormItem key="form_address_remark" type="textarea" title="详细地址" :data.sync="data" field="address_remark" value="最多80个字"
            maxlength="80" row="2"></nFormItem>
        <nFormItem key="form_remark" type="textarea" title="商家介绍" :data.sync="data" field="remark" value="最多200个字"
            maxlength="200"></nFormItem>
        <nBar title="拓展信息"></nBar>
        <nFormItem key="form_gold_coupon_ratio" title_em="6" title="金券赠送比例" :data.sync="data" field="gold_coupon_ratio" format="number"></nFormItem>
        <nBar title="图片信息"></nBar>
        <nFormItem key="form_logo" type="image" image_mode="scaleToFill" title="商家正面Logo" value="建议: 宽高1:1 最大像素750*750" :data.sync="data"
            field="logo"></nFormItem>
        <nFormItem key="form_banner" type="image" image_mode="scaleToFill" title="商家列表页banner" value="建议: 最大像素750*350" :data.sync="data"
            field="banner" image_height="322"></nFormItem>
        <nFormItem key="form_album_1" type="image" title_em="5" title="商家图片1" value="建议: 最大宽度像素750" :data.sync="data" field="album_1"></nFormItem>
        <nFormItem key="form_album_2" type="image" title_em="5" title="商家图片2" value="建议: 最大宽度像素750" :data.sync="data" field="album_2"></nFormItem>
        <nFormItem key="form_album_3" type="image" title_em="5" title="商家图片3" value="建议: 最大宽度像素750" :data.sync="data" field="album_3"></nFormItem>
        <foot title="修改店铺信息" :tap="update"></foot>
        <modalDialog :show.sync="dialog.show" :content="dialog.content" :is_hide_cancel="true"></modalDialog>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                dialog: {
                    content: '',
                    show: false,
                },
                data: {
                    formtag: {},
                    form: {}
                }
            }
        },
        onLoad() {
            this.pageInit();
        },
        watch: {
            'data.form.is_express'(new_value) {
                if (new_value == 1) {
                    if (this.$store.state.user.is_pay_open_express_seller_firm == 0) {
                        this.data.form.is_express = 0;
                        this.dialog.show = true;
                        if (this.$store.state.user.is_annual_fee_end_date_seller_firm == 0) {
                            // 缴年费
                            this.dialog.content = '需要先缴年费，请在固定信息中选择';
                        } else {
                            // 开始全国邮寄
                            this.dialog.content = '需要先开通全国邮寄，请在固定信息中选择';
                        }

                    }
                }
            }
        },
        methods: {
            pageInit() {
                this.$set(this.data, 'form', {
                    address_remark: this.$store.state.user.identity_info.seller_info.address_remark,
                    contact_phone: this.$store.state.user.identity_info.seller_info.contact_phone,
                    remark: this.$store.state.user.identity_info.seller_info.remark,
                    gold_coupon_ratio: this.$store.state.user.identity_info.seller_info.gold_coupon_ratio,

                    open_start_time: this.$store.state.user.identity_info.seller_info.open_start_time,
                    open_end_time: this.$store.state.user.identity_info.seller_info.open_end_time,
                    is_to_shop: this.$store.state.user.identity_info.seller_info.is_to_shop,
                    is_same_city_tmp: this.$store.state.user.identity_info.seller_info.is_same_city > 0 ? 1 : 0,
                    is_same_city: this.$store.state.user.identity_info.seller_info.is_same_city,
                    is_express: this.$store.state.user.identity_info.seller_info.is_express,
                    same_city_price: this.$nddyny.number.floor(this.$store.state.user.identity_info.seller_info
                        .same_city_price),

                    logo: this.$store.state.user.identity_info.seller_info.logo,
                    banner: this.$store.state.user.identity_info.seller_info.banner || this.$store.state.user.identity_info.seller_info.logo,
                    album_1: this.$store.state.user.identity_info.seller_info.album_1,
                    album_2: this.$store.state.user.identity_info.seller_info.album_2,
                    album_3: this.$store.state.user.identity_info.seller_info.album_3,
                });
            },
            update() {
                if (this.data.form.is_same_city_tmp == 1 && this.data.form.is_same_city == 0) {
                    this.dialog.show = true;
                    this.dialog.content = '请填写同城配送距离';
                    return;
                }
                this.$api.post(this, {
                    loading: '修改信息中',
                    url: '/seller/info/update',
                    upload: {
                        uri: '/seller/info/upload',
                        fields: ['logo', 'banner', 'album_1', 'album_2', 'album_3'],
                        info_old: this.$store.state.user.identity_info.seller_info,
                        info_new: this.data.form
                    },
                    data_append: {
                        is_same_city: this.data.form.is_same_city_tmp == 0 ? 0 : this.data.form.is_same_city,
                    },
                    success: (Result) => {
                        if (this.$api.form.toast(this, Result)) return;
                        this.$user.updateIdentityInfo(this, () => {
                            this.pageInit();
                        });
                        this.$store.commit('userToastSuccess', '修改信息成功');
                    }
                });
            },
        }
    }
</script>
